
/***
 * Generates vessel mask file for DSA image sequences.
 *
 */

#include <cstdlib> 
#include <iostream>

using namespace std;

#include "dsaio.h"
#include "vessel_mask.h"

int main ( int argc, char **argv )
{
  // process command line args
  if ( argc != 3 && argc != 5 )
  {
    cout << "Usage: " << argv[ 0 ] << " input output [from to]" << endl;
    return -1;
  }
  char *input_file_name = argv[ 1 ];
  char *output_file_name = argv[ 2 ];
  int from_frame = 0;
  int to_frame = dsa_frame_count ( input_file_name );
  if ( argc == 5 )
  {
    from_frame = atoi ( argv[ 3 ] );
    to_frame = atoi ( argv[ 4 ] );
  }
  
  // debug
  cerr << "Input:  " << input_file_name << endl;
  cerr << "Output: " << output_file_name << endl;
  cerr << "From frame: " << from_frame << endl;
  cerr << "To frame:   " << to_frame << endl;
  
  // process frames
  for ( int i = from_frame; i <= to_frame; ++ i )
  {
    cerr << "Processing frame " << i << endl;
    DsaFrame::Pointer frame = dsa_get_frame ( input_file_name, i );
    DsaFrame::Pointer vm = vessel_mask ( frame );
    dsa_append_frame ( output_file_name, vm );
  }
  
  return 0;
}
